package com.fenghongzhang.day005;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;


/**
 * A simple {@link Fragment} subclass.
 */
public class LeftFragment extends Fragment {
    private EditText fgEdit;

    private Button btn;
    public LeftFragment() {
        // Required empty public constructor
    }

    public interface MyListener {
        void send(String s);
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
    }

    private MyListener myListener;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_send, container, false);
        fgEdit = (EditText) inflate.findViewById(R.id.fg_edit);
        btn = (Button) inflate.findViewById(R.id.btn);
        //赋值

//        getActivity().getSupportFragmentManager()
        //fragment嵌套
        FragmentManager childFragmentManager = getChildFragmentManager();
        FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
//        fragmentTransaction.add()
        fragmentTransaction.commit();


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = fgEdit.getText().toString();
                myListener.send(string);
            }
        });
        return inflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        myListener = (MyListener) getActivity().getSupportFragmentManager().findFragmentByTag("right");
    }
}
